package svc

import (
	"gitcode.com/sunsungk9/opensource-demo-cockroachdb-obs-241123/user/internal/config"
	// _ "gitee.com/opengauss/openGauss-connector-go-pq"

	_ "github.com/jackc/pgx/v5/stdlib"

	"xorm.io/xorm"
)

type ServiceContext struct {
	Config config.Config
	DB     *xorm.Engine
}

func NewServiceContext(c config.Config) *ServiceContext {
	db, err := xorm.NewEngine("pgx", c.DSN)
	if err != nil {
		panic(err)
	}

	err = db.Ping()
	if err != nil {
		panic(err)
	}

	db.ShowSQL(true)

	return &ServiceContext{
		Config: c,
		DB:     db,
	}
}
